/*    */ package my.rummySave;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.IOException;
/*    */ import java.io.ObjectOutputStream;
/*    */ import javax.swing.JFileChooser;
/*    */ import javax.swing.filechooser.FileSystemView;
/*    */ import my.rummyInterface.RummyInterface;
/*    */ 
/*    */ public class Salvar
/*    */ {
/*    */   private RummyInterface principal;
/*    */   private JuegoSalvar grabar;
/*    */   private File filename;
/*    */ 
/*    */   public static File getWorkingDirectory(String applicationName)
/*    */     throws Exception
/*    */   {
/* 22 */     JFileChooser fr = new JFileChooser();
/* 23 */     FileSystemView fw = fr.getFileSystemView();
/* 24 */     File userDirectory = fw.getDefaultDirectory();
/* 25 */     String userHome = userDirectory.getPath() + "/Rummy/Juegos Guardados/";
/*    */ 
/* 27 */     if (!new File(userHome).exists()) {
/* 28 */       boolean success = new File(userHome).mkdirs();
/* 29 */       if (!success) {
/* 30 */         throw new Exception("Nope");
/*    */       }
/*    */     }
/* 33 */     File workingDirectory = new File(userHome + applicationName);
/* 34 */     return workingDirectory;
/*    */   }
/*    */ 
/*    */   public Salvar(String app, RummyInterface p)
/*    */     throws Exception
/*    */   {
/* 47 */     this.principal = p;
/*    */     try {
/* 49 */       this.filename = getWorkingDirectory(app + ".rummy");
/*    */     }
/*    */     catch (Exception ex)
/*    */     {
/* 53 */       ex.printStackTrace();
/*    */     }
/* 55 */     this.grabar = new JuegoSalvar(this.principal);
/* 56 */     FileOutputStream fos = null;
/* 57 */     ObjectOutputStream out = null;
/*    */     try
/*    */     {
/* 60 */       fos = new FileOutputStream(this.filename);
/* 61 */       out = new ObjectOutputStream(fos);
/* 62 */       out.writeObject(this.grabar);
/* 63 */       out.close();
/*    */     }
/*    */     catch (IOException ex)
/*    */     {
/* 67 */       ex.printStackTrace();
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Yank\Documents\APO\Rummy\bin\
 * Qualified Name:     my.rummySave.Salvar
 * JD-Core Version:    0.6.0
 */